<#assign module="member"/>

<@override name="header">
<link rel="stylesheet" href="${ctx}/assets/css/jquery.Jcrop.css">
</@override>
<@override name="body">

	<div class="row">
		<div class="col-md-12 col-lg-12">
			<div class="table-responsive">
				<div class="panel panel-default">
					<div class="panel-heading">
						编辑客户信息
					</div>
					<div class="panel-body">
    				<form class="form-horizontal" id="submit_form" action="${ctx}/member/updatePersonal" method="post">
		                <input type="hidden" name="CSRFToken" value="${CSRFToken}"/>
						<input type="hidden" name="id" value="${passenger.id}">
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">客户类型：</label>
		                   	<div class="col-sm-3">
		                   		<p class="form-control-static">${passenger.typeStr}</p>
		               		</div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">客户头像：</label>
		                    <div class="col-sm-3">
			                    <img width="150" height="150" <#if passenger.photo??>src="${ctx}/upload/member/${passenger.photo}"<#else>src="${ctx}/assets/css/images/member_img.png"</#if> />
		                	</div>
		                </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">身份证图片：</label>
                            <div class="col-sm-3">
                                <img width="150" height="150" <#if passenger.idCardPhoto??>src="${ctx}/upload/member/idCard/${passenger.idCardPhoto}"<#else>src="${ctx}/assets/css/images/member_img.png"</#if> />
                            </div>
                            <div class="col-sm-3">
                                <img width="150" height="150" <#if passenger.idCardBackPhoto??>src="${ctx}/upload/member/idCard/${passenger.idCardBackPhoto}"<#else>src="${ctx}/assets/css/images/member_img.png"</#if> />
                            </div>
                        </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label"><em>*</em>联系人：</label>
		                   	<div class="col-sm-3">
		                   		<input class="form-control" id="name" name="name" type="text" value="${passenger.name?if_exists}" required />
		                	</div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label"><em>*</em>手机号：</label>
		                   	<div class="col-sm-3">
		                   		<input class="form-control" id="phoneShow" name="phoneShow" type="text" value="${passenger.phoneShow?if_exists}" required />
		                   		<div style="display:none">
		                   			<input class="form-control" id="phone" name="phone" type="text" value="${passenger.phone?if_exists}" hidden/>
		               			</div>
		               		</div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">性别：</label>
		                	<div class="col-sm-3">
		                		<label style="margin-right:50px;">
		                			<p class="form-control-static">
							  			<input type="radio" name="gender" value="0" <#if passenger.gender?? && passenger.gender==0>checked="checked"</#if> />男
							  		</p>
							  	</label>
							  	
							  	<label>
							  		<p class="form-control-static">
							  		<input type="radio" name="gender" value="1" <#if passenger.gender?? && passenger.gender==1>checked="checked"</#if> />女
							  		</p>
							  	</label>
							</div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label"><em>*</em>客户等级：</label>
		                    <div class="col-sm-3">
			                    <select class="form-control" id="grade_id" name="grade_id" required />
									<option value="">--无--</option>
									<#if grades??>
										<#list grades as grade>
											<option value="${grade.id}" <#if passenger.grade_id?? && passenger.grade_id==grade.id>selected="selected"</#if>>${grade.name?if_exists}</option>
										</#list>
									</#if>
								</select>
		                	</div>
		                </div>
		                <div class="form-group">
		                    <label class="col-sm-3 control-label"><em>*</em>所属公司：</label>
		                    <div class="col-sm-3">
			                    <select class="form-control" id="companyId" name="companyId" required>
			                    	<#list companys as company>
			                    		<#if ismain>
			                    			<option value="${company.id}" <#if passenger.companyId==company.id>selected="selected"</#if>>${company.abbreviation?if_exists}</option>
			                    		<#else>
			                    			<#if passenger.companyId==company.id>
			                    				<option value="${company.id}" selected="selected">${company.abbreviation?if_exists}</option>
			                    			</#if>
			                    		</#if>
									</#list>
			                    </select>
		                	</div>
		                </div>
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">身份证：</label>
		                   	<div class="col-sm-3">
		                   		<input class="form-control" id="idcard" name="idcard" type="text" value="${passenger.idcard?if_exists}" />
		               		</div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">电子邮件：</label>
		                   	<div class="col-sm-3">
		                   		<input class="form-control" id="email" name="email" type="email" value="${passenger.email?if_exists}" />
		               		</div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">客户来源：</label>
		                    <div class="col-sm-3">
		                    	<input class="form-control" id="channel_name" name="channel_name" type="text" value="${passenger.channel_name?if_exists}" />
		                	</div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">推荐人：</label>
		                    <div class="col-sm-3">
		                    	<input class="form-control" id="introducer" name="introducer" type="text" value="${passenger.introducer?if_exists}"/>
		                	</div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">推荐人类型：</label>
		                    <div class="col-sm-3">
		                    	<p class="form-control-static">
		                    		<label style="padding-right:30px;">
										<input type="radio" name="introduceType" value="0" <#if passenger.introduceType?? && passenger.introduceType==0>checked="checked"</#if>> 客户推荐
									</label>
									<label style="padding-right:30px;">
										<input type="radio" name="introduceType" value="1" <#if passenger.introduceType?? && passenger.introduceType==1>checked="checked"</#if>> 服务人员推荐
									</label>
								</p>
		                	</div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">常用目的地：</label>
		                    <div class="col-sm-3">
		                    	<input class="form-control" id="address" name="address" type="text" value="${passenger.address?if_exists}" readOnly />
		                	</div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">紧急联系人姓名：</label>
		                    <div class="col-sm-3">
		                    	<input class="form-control" id="memberEcn" name="memberEcn" type="text" value="${passenger.memberEcn?if_exists}" readOnly />
		                	</div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">紧急联系人电话：</label>
		                    <div class="col-sm-3">
		                    	<input class="form-control" id="memberEcp" name="memberEcp" type="text" value="${passenger.memberEcp?if_exists}" readOnly />
		                	</div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">车牌号：</label>
		                    <div class="col-sm-3">
		                    	<input class="form-control" id="plateNumber" name="plateNumber" type="text" value="${passenger.plateNumber?if_exists}" />
		                	</div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">备注：</label>
		                    <div class="col-sm-3">
		                    	<textarea class="form-control" cols="20" id="memo" name="memo" rows="2">${passenger.memo?if_exists}</textarea>
		                	</div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label">是否允许签单：</label>
	                    	<div class="col-sm-3">
	                    	<p class="form-control-static">
							  <input <@shiro.lacksPermission name='allowsign'>disabled="disabled"</@shiro.lacksPermission> type="checkbox" name="allowOverdraw" <#if passenger.allowOverdraw??>${passenger.allowOverdraw?string('checked="checked"','')}</#if>/>
							</p>
							</div>
		                </div>
		                
		                <div class="form-group">
		                	<div class="col-sm-3">
		                	</div>
		                	<div class="col-sm-3">
		                		<@shiro.hasPermission name='memberedit'>
				                <input id="submit_button" type="submit" class="btn btn-primary" value="保存">
				                </@shiro.hasPermission>
				                <input type="button" class="btn btn-default" onclick="window.location.href = '${ctx}/member/list';" value="返回">
			            	</div>
			            </div>
		            </form>
		        	</div>
				</div>
			</div>
		</div>
	</div>


</@override>
<@override name="footer">
<script type="text/javascript">
	<#if message??>
		$.scojs_message("${message}", $.scojs_message.TYPE_ERROR);
	</#if>
	$(document).ready(function(){
		$("#submit_form").submit(function(){
			var isphone=/^\+?\d{3,13}(\-?(\d{6,8}?))?(\-?(\d{4,8}?))*$/; 
			
			var phone=$("#phone").val();
			if (!isphone.test(phone)){
				$.scojs_message("手机号格式不正确", $.scojs_message.TYPE_ERROR);
				return false;
			}
			var grade_id=$("#grade_id").val();
			if (grade_id == null || grade_id.trim()=="" || grade_id.trim()=="无"){
				$.scojs_message("客户等级不能为空", $.scojs_message.TYPE_ERROR);
				return false;
			}
			$("#submit_button").attr("disabled",true);
			$.post($(this).attr("action"),$(this).serialize(),function(data){
	            if(data.success){
	                $.scojs_message('修改成功', $.scojs_message.TYPE_OK);
	                window.location='${ctx}/member/list';
	            }
	            else {
	            	$("#submit_button").attr("disabled",false);
	            	$("#CSRFToken").val(data.object);
	            	$.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
	            }
		    },'json');
			
			return false;
			
		});
		
		$(document).on("change","#phoneShow",function(){
			$("#phone").val($("#phoneShow").val());
		});
		
		$(document).on("change","#companyId",function(){
			$.ajax({
		        url : '${ctx}/member/findByCompany',
		        type:'GET',
		        async:false,
		        dataType : 'json',
		        data : {
		        	"companyId":$(this).val()
		        },
		        success : function(result){
		        	if(result.success) {
	        			$("#grade_id").html('');
		        		if (result.data != null) {
		        			$(result.data).each(function(index,element){
		        				var text="<option value="+result.data[index].id+">"+result.data[index].name+"</option>";
		            			$("#grade_id").append(text);
							 });
		        		} else {
		        			var text="<option>无</option>";
		        			$("#grade_id").append(text);
		        		}
		        	}
		        }
		     });
		});
		
	});
</script>
</@override>
<@extends name="../layout.ftl"/>